package com.pussinboots.morning.cms.modules.system.product.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.pussinboots.morning.cms.modules.system.category.entity.OsCategory;
import com.pussinboots.morning.cms.modules.system.product.entity.OsProductCategory;
import com.pussinboots.morning.cms.modules.system.product.mapper.OsProductCategoryMapper;
import com.pussinboots.morning.cms.modules.system.product.service.IOsProductCategoryService;
import com.pussinboots.morning.common.model.PageInfo;

/**
 * <p>
 * 商品分类关联表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2017-04-12
 */
@Service
public class OsProductCategoryServiceImpl extends ServiceImpl<OsProductCategoryMapper, OsProductCategory> implements IOsProductCategoryService {
	
	@Autowired
	private OsProductCategoryMapper productCategoryMapper;
	
	
	@Override
	public PageInfo selectByPullPage(PageInfo pageInfo) {

		//设置分页
		Page<OsProductCategory> page = new Page<>(pageInfo.getNowpage(), pageInfo.getSize());
		
		//设置排序
		String sortStr = pageInfo.getSort();
		
		//查询数据
		List<OsProductCategory> osProductCategoryList = null;
		if(sortStr!=null && !sortStr.equals("")){
			osProductCategoryList = productCategoryMapper.selectPage(page, new EntityWrapper<OsProductCategory>().orderBy(sortStr, false));
		}else{
			osProductCategoryList = productCategoryMapper.selectPage(page, null);
		}
		
		//设置返回对象
        pageInfo.setTotal(page.getTotal());
        pageInfo.setRows(osProductCategoryList);
        
        //返回数据
		return pageInfo;
	}


	@Override
	public OsCategory queryCategoryOfProductByPid(Long productId) {
		OsCategory  entity = productCategoryMapper.queryCategoryByProductId(productId);
		return entity;
	}
	
	
}
